package logic

import (
	"context"
	"fmt"
	"library/models/mysql"

	"library/library/internal/svc"
	"library/library/library"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentLogic {
	return &AddCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddCommentLogic) AddComment(in *library.AddCommentRequest) (*library.AddCommentResponse, error) {
	// todo: add your logic here and delete this line

	comment := mysql.Comment{
		UserId:     in.UserId,
		ActivityId: in.ActivityId,
		Context:    in.Context,
	}
	err := mysql.DB.Debug().Create(&comment).Error
	if err != nil {
		return nil, fmt.Errorf("用户留言成功")
	}

	return &library.AddCommentResponse{Id: int64(comment.ID)}, nil
}
